/* -*- Mode: C; c-basic-offset: 4 -*-
 * pygtk- Python bindings for the GTK toolkit.
 * Copyright (C) 2007  Mariano Suárez-Alvarez
 *
 *   gtkborder.override: gtk.Border overrides
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */
%%
override gtk_border_new kwargs
static int
_wrap_gtk_border_new(PyGBoxed *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "left", "right", "top", "bottom", NULL };
    GtkBorder border = {0, 0, 0, 0};

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
				     "|iiii:GdkRectangle.__init__",
				     kwlist, &border.left, &border.right,
				     &border.top, &border.bottom))
	return -1;

    self->boxed = g_boxed_copy(GTK_TYPE_BORDER, &border);
    self->free_on_dealloc = TRUE;
    self->gtype = GTK_TYPE_BORDER;
    
    return 0;
}
%%
override-slot GtkBorder.tp_as_sequence
static Py_ssize_t
_wrap_gtk_border_length(PyGBoxed *self)
{
    return 4;
}
static PyObject *
_wrap_gtk_border_getitem(PyGBoxed *self, Py_ssize_t pos)
{
    GtkBorder *border;

    if (pos < 0)
        pos += 4;
    if (pos < 0 || pos >= 4) {
        PyErr_SetString(PyExc_IndexError, "index out of range");
        return NULL;
    }
    border = pyg_boxed_get(self, GtkBorder);
    switch (pos) {
    case 0: return PyInt_FromLong(border->left);
    case 1: return PyInt_FromLong(border->right);
    case 2: return PyInt_FromLong(border->top);
    case 3: return PyInt_FromLong(border->bottom);
    default:
        g_assert_not_reached();
        return NULL;
    }
}
static int
_wrap_gtk_border_setitem(PyGBoxed *self, Py_ssize_t pos, PyObject *value)
{
    GtkBorder *border;
    gint val;

    if (pos < 0)
        pos += 4;
    if (pos < 0 || pos >= 4) {
        PyErr_SetString(PyExc_IndexError, "index out of range");
        return -1;
    }
    border = pyg_boxed_get(self, GtkBorder);
    val = PyInt_AsLong(value);
    if (PyErr_Occurred())
        return -1;
    switch(pos) {
    case 0: border->left   = val; break;
    case 1: border->right  = val; break;
    case 2: border->top    = val; break;
    case 3: border->bottom = val; break;
    default:
        g_assert_not_reached();
        return -1;
    }
    return 0;
}
static PySequenceMethods _wrap_gtk_border_tp_as_sequence = {
    (lenfunc)_wrap_gtk_border_length,
    0,
    0,
    (ssizeargfunc)_wrap_gtk_border_getitem,
    0,
    (ssizeobjargproc)_wrap_gtk_border_setitem,
    0,
};
%%
override-attr GtkBorder.left
static int
_wrap_gtk_border__set_left(PyGBoxed *self, PyObject *value, void *closure)
{
    gint val;

    val = PyInt_AsLong(value);
    if (PyErr_Occurred())
        return -1;
    pyg_boxed_get(self, GtkBorder)->left = val;
    return 0;
}
%%
override-attr GtkBorder.right
static int
_wrap_gtk_border__set_right(PyGBoxed *self, PyObject *value, void *closure)
{
    gint val;

    val = PyInt_AsLong(value);
    if (PyErr_Occurred())
        return -1;
    pyg_boxed_get(self, GtkBorder)->right = val;
    return 0;
}
%%
override-attr GtkBorder.top
static int
_wrap_gtk_border__set_top(PyGBoxed *self, PyObject *value, void *closure)
{
    gint val;

    val = PyInt_AsLong(value);
    if (PyErr_Occurred())
        return -1;
    pyg_boxed_get(self, GtkBorder)->top = val;
    return 0;
}
%%
override-attr GtkBorder.bottom
static int
_wrap_gtk_border__set_bottom(PyGBoxed *self, PyObject *value, void *closure)
{
    gint val;

    val = PyInt_AsLong(value);
    if (PyErr_Occurred())
        return -1;
    pyg_boxed_get(self, GtkBorder)->bottom = val;
    return 0;
}

